{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b8e3e027",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:44:45.762432Z",
     "start_time": "2021-11-01T06:44:45.748916Z"
    }
   },
   "outputs": [],
   "source": [
    "info = {\n",
    "    \"stu1001\":\"anny\",\n",
    "    \"stu1002\":\"ben\",\n",
    "    \"stu1003\":\"lili\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bc0fb99b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:44:51.238858Z",
     "start_time": "2021-11-01T06:44:51.215295Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu1001': 'anny', 'stu1002': 'ben', 'stu1003': 'lili'}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "81e141ec",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:45:19.655713Z",
     "start_time": "2021-11-01T06:45:19.638707Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu1001\n",
      "stu1002\n",
      "stu1003\n"
     ]
    }
   ],
   "source": [
    "# 循环遍历一个字典\n",
    "\n",
    "#循环遍历整个内容怎么做：\n",
    "\n",
    "for i in info:\n",
    "    print(i)# 打印key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b9b8425f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:48:56.867482Z",
     "start_time": "2021-11-01T06:48:56.862493Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu1001 anny\n",
      "stu1002 ben\n",
      "stu1003 lili\n"
     ]
    }
   ],
   "source": [
    "# 循环遍历整个字典的items\n",
    "# for k,v in info:\n",
    "#     print(k,v)\n",
    "#-----------------------wrong------------\n",
    "for k,v in info.items():\n",
    "    print(k,v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "351e081d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:54:04.980474Z",
     "start_time": "2021-11-01T06:54:04.963079Z"
    }
   },
   "outputs": [],
   "source": [
    "# 实践1：\n",
    "# stu1801 中 取出数字，作为新的字典key\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "# 字典新增方式：\n",
    "    new_info[k[3:]] = v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3de5a643",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:54:13.419508Z",
     "start_time": "2021-11-01T06:54:13.398955Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'1001': 'anny', '1002': 'ben', '1003': 'lili'}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "612a394d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:57:55.676239Z",
     "start_time": "2021-11-01T06:57:55.670239Z"
    }
   },
   "outputs": [],
   "source": [
    "# 实践2：\n",
    "# vlew改变所有字母大写\n",
    "new_info2 = {}\n",
    "for k,v in info.items():\n",
    "     new_info2[k[3:]] = v.upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "31984f68",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T07:01:33.999528Z",
     "start_time": "2021-11-01T07:01:33.984828Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1001: 'ANNY', 1002: 'BEN', 1003: 'LILI'}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_info2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "cbe6b6c5",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T07:01:29.983991Z",
     "start_time": "2021-11-01T07:01:29.971922Z"
    }
   },
   "outputs": [],
   "source": [
    "# 实践3：\n",
    "# 让new_info key 由'1801'==》1801\n",
    "new_info2 = {}\n",
    "for k,v in info.items():\n",
    "     new_info2[int(k[3:])] = v.upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "131b347f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.4"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
